/*------------------------------------------------------------------------------
--                                                                            --
--       This software is confidential and proprietary and may be used        --
--        only as expressly authorized by a licensing agreement from          --
--                                                                            --
--                            Hantro Products Oy.                             --
--                                                                            --
--                   (C) COPYRIGHT 2006 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--                 The entire notice above must be reproduced                 --
--                  on all copies and should not be removed.                  --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Description : H.264 Decoder API
--
--------------------------------------------------------------------------------
--
--  Version control information, please leave untouched.
--
--  $RCSfile: h264decapi.h,v $
--  $Date: 2006/10/02 11:40:53 $
--  $Revision: 1.9 $
--
------------------------------------------------------------------------------*/

#ifndef __H264DECAPI_H__
#define __H264DECAPI_H__

#ifdef __cplusplus
extern "C"
{
#endif

#include "basetype.h"

/*------------------------------------------------------------------------------
    API type definitions
------------------------------------------------------------------------------*/

    /* Return values */
    typedef enum H264DecRet_
    {
        H264DEC_OK = 0,
        H264DEC_STRM_PROCESSED = 1,
        H264DEC_PIC_RDY = 2,
        H264DEC_PIC_RDY_BUFF_NOT_EMPTY = 3,

        H264DEC_HDRS_RDY_BUFF_NOT_EMPTY = 6,
        H264DEC_NEW_HDRS_BUFF_NOT_EMPTY = 7,

        H264DEC_ADVANCED_TOOLS_BUFF_NOT_EMPTY = 8,

        H264DEC_FREEZED_PIC_RDY_BUFF_NOT_EMPTY = 9,
        H264DEC_FREEZED_PIC_RDY = 10,

        H264DEC_PARAM_ERROR = -1,
        H264DEC_STRM_ERROR = -2,
        H264DEC_NOT_INITIALIZED = -3,
        H264DEC_MEMFAIL = -4,
        H264DEC_INITFAIL = -5,
        H264DEC_HDRS_NOT_RDY = -6,
        H264DEC_STREAM_NOT_SUPPORTED = -8,

        H264DEC_HW_RESERVED = -254,
        H264DEC_HW_TIMEOUT = -255,
        H264DEC_HW_BUS_ERROR = -256,
        H264DEC_SYSTEM_ERROR = -257,
        H264DEC_DWL_ERROR = -258
    } H264DecRet;

    /* decoder  output picture format */
    typedef enum H264DecOutFormat_
    {
        H264DEC_SEMIPLANAR_YUV420 = 0x020001,
        H264DEC_TILED_YUV420 = 0x020002
    } H264DecOutFormat;

    /* Decoder instance */
    typedef void *H264DecInst;

    /* Input structure */
    typedef struct H264DecInput_
    {
        u8 *pStream;    /* Pointer to the input */
        u32 streamBusAddress; /* DMA bus address of the input stream */
        u32 dataLen;    /* Number of bytes to be decoded         */
        u32 picId;  /* Identifier for the picture to be decoded */
    } H264DecInput;

    /* Output structure */
    typedef struct H264DecOutput_
    {
        u8 *pStrmCurrPos;   /* Pointer to stream position where decoding ended */
        u32 strmCurrBusAddress; /* DMA bus address location where the decoding ended */
    } H264DecOutput;

    /* Output structure for H264DecNextPicture */
    typedef struct H264DecPicture_
    {
        u32 *pOutputPicture;    /* Pointer to the picture */
        u32 outputPictureBusAddress;  /* DMA bus address of the output picture buffer */
        u32 picId;  /* Identifier of the picture to be displayed */
        u32 isIdrPicture;   /* Indicates if picture is an IDR picture */
        u32 nbrOfErrMBs;    /* Number of concealed MB's in the picture  */
    } H264DecPicture;

    /* cropping info */
    typedef struct H264CropParams_
    {
        u32 cropLeftOffset;
        u32 cropOutWidth;
        u32 cropTopOffset;
        u32 cropOutHeight;
    } H264CropParams;

    /* stream info filled by H264DecGetInfo */
    typedef struct H264DecInfo_
    {
        u32 picWidth;
        u32 picHeight;
        u32 videoRange;
        u32 matrixCoefficients;
        u32 croppingFlag;
        H264CropParams cropParams;
        H264DecOutFormat outputFormat; /* format of the output picture */
        u32 sarWidth;
        u32 sarHeight;
    } H264DecInfo;

    /* Version information */
    typedef struct H264DecApiVersion_
    {
        u32 major;  /* API major version */
        u32 minor;  /* API minor version */
    } H264DecApiVersion;

    typedef struct H264DecBuild_
    {
        u32 swBuild;    /* Software build ID */
        u32 hwBuild;    /* Hardware build ID */
    } H264DecBuild;

/*------------------------------------------------------------------------------
    Prototypes of Decoder API functions
------------------------------------------------------------------------------*/

    H264DecApiVersion H264DecGetAPIVersion(void);

    H264DecBuild H264DecGetBuild(void);

    H264DecRet H264DecInit(H264DecInst * pDecInst, u32 noOutputReordering,
                           u32 disablePicFreezeErrorConceal);

    void H264DecRelease(H264DecInst decInst);

    H264DecRet H264DecDecode(H264DecInst decInst,
                             H264DecInput * pInput, H264DecOutput * pOutput);

    H264DecRet H264DecNextPicture(H264DecInst decInst,
                                  H264DecPicture * pOutput, u32 endOfStream);

    H264DecRet H264DecGetInfo(H264DecInst decInst, H264DecInfo * pDecInfo);

/*------------------------------------------------------------------------------
    Prototype of the API trace funtion. Traces all API entries and returns.
    This must be implemented by the application using the decoder API!
    Argument:
        string - trace message, a null terminated string
------------------------------------------------------------------------------*/
    void H264DecTrace(const char *string);
    
    void * GetH264DWLInst(H264DecInst pDecInst);

    void SetDispReplaceMap(u32 index, u32 dispPicVirtual, u32 dispPicLinear, 
                        u32 RepPicVirtual, u32 RepPicLinear);
    void InitDispReplaceMap();
    
#ifdef __cplusplus
}
#endif

#endif /* __H264DECAPI_H__ */
